//
//  InsurancePointCell.m
//  CarUser
//
//  Created by 王森林 on 2019/1/18.
//  Copyright © 2019年 王森林. All rights reserved.
//

#import "InsurancePointCell.h"

@interface InsurancePointCell()
@property (nonatomic, strong) NSDictionary *dict;
@property (nonatomic, strong) UIView *topView;
@end

@implementation InsurancePointCell

- (void)createUIWithData
{
    
    [self.contentView removeAllSubviews];
    [self.contentView addSubview:self.topView];
    self.topView.frame = CGRectMake(15, 15, BOUNDWIDTH - 30, 36);
    UILabel *topLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 100, 16)];
    topLabel.text = @"保险服务";
    topLabel.font = FONT_SIZE(15);
    topLabel.textColor = RGB(242, 242, 242);
    [self.topView addSubview:topLabel];
    
    UIButton *delBtn  = [UIButton buttonWithType:UIButtonTypeCustom];
    delBtn.frame = CGRectMake(BOUNDWIDTH - 60-15-30, 10, 60, 16);
    [delBtn setTitle:@"删除" forState:UIControlStateNormal];
    [delBtn setTitleColor:Common_NavigroundColor forState:UIControlStateNormal];
    [delBtn setBackgroundColor:RGB(254, 218, 60)];
    delBtn.layer.cornerRadius = 8;
    delBtn.layer.masksToBounds = YES;
    delBtn.titleLabel.font = FONT_SIZE(12);
    [delBtn addTarget:self action:@selector(handleDelAction) forControlEvents:UIControlEventTouchUpInside];
    [self.topView  addSubview:delBtn];
    
    
    for  (int  i = 0 ; i<6; i++) {
        UIView *functionBGView = [[UIView alloc] initWithFrame:CGRectMake(15+(BOUNDWIDTH-30)/2*(i%2), 65+20*(i/2), (BOUNDWIDTH-30)/2, 15)];
        [self.contentView addSubview:functionBGView];
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10,(15-4)/2 , 4, 4)];
        label.layer.cornerRadius = 2;
        label.layer.masksToBounds = YES;
        label.backgroundColor = [UIColor blackColor];
        [functionBGView addSubview:label];
        
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, (BOUNDWIDTH-30)/2-20, 15)];
        titleLabel.textColor = RGB(102, 102, 102);
        titleLabel.font = FONT_SIZE(14);
        [functionBGView addSubview:titleLabel];
        
        switch (i) {
            case 0:
            {
                titleLabel.text = [NSString stringWithFormat:@"保险类型:%@",[self.dict objectForKey:@"DNAME2"]];
                
            }
                break;
            case 1:
            {
             
                 titleLabel.text = [NSString stringWithFormat:@"车牌号:%@",[self.dict objectForKey:@"CP0000"]];
                
            }
                break;
            case 2:
            {
               
                     titleLabel.text = [NSString stringWithFormat:@"联系人:%@",[self.dict objectForKey:@"LXR000"]];
                
            }
                break;
            case 3:
            {
                  titleLabel.text = [NSString stringWithFormat:@"联系电话:%@",[self.dict objectForKey:@"LXDH00"]];
                
            }
                break;
            case 4:
            {
               
                  titleLabel.text = [NSString stringWithFormat:@"所在城市:%@",[self.dict objectForKey:@"SZCS00"]];
                
            }
                break;
            case 5:
            {
               
                 titleLabel.text = [NSString stringWithFormat:@"预约日期:%@",[self.dict objectForKey:@"YYRQ00"]];
                
            }
                break;
                
            default:
                break;
        }

        
    }
    
    
}


- (void)handleDelAction
{
    if (self.resultBlock) {
        self.resultBlock([self.dict objectForKey:@"INSURANCE_ID"]);
    }
    
    
}

- (void)setData:(id)data
{
    if (data) {
        
        self.dict = [NSDictionary dictionaryWithDictionary:data];
       [self createUIWithData];
    }

    
}

- (UIView *)topView
{
    if (!_topView) {
        _topView  = [UIView new];
        _topView.backgroundColor = Common_NavigroundColor;
    }
    return _topView;
}

@end
